package com.yl.config.captcha;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * google验证码 配置
 *
 * @Author jiangtao
 * @CreateBy 2019-01-16 10:31 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 * https://www.cnblogs.com/yangzhilong/p/8574685.html
 * http://www.xuebuyuan.com/981239.html
 */
@Configuration
public class CaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha() {
        Properties kaptchaProperties = new Properties();
        kaptchaProperties.put("kaptcha.border", "no");

        kaptchaProperties.put("kaptcha.image.height", "40");
        kaptchaProperties.put("kaptcha.image.width", "150");


        kaptchaProperties.put("kaptcha.textproducer.font.color", "0,0,0");
        kaptchaProperties.put("kaptcha.textproducer.font.size", "32");
        kaptchaProperties.put("kaptcha.textproducer.char.space", "6");
        kaptchaProperties.put("kaptcha.textproducer.char.length", "5");
        kaptchaProperties.put("kaptcha.textproducer.char.string", "abcde2345678gfynmnpwx");
        kaptchaProperties.put("kaptcha.textproducer.font.names", "Consolas,Helvetica,sans-serif,Arial");

        kaptchaProperties.put("kaptcha.background.clear.to", "255,255,255");
        kaptchaProperties.put("kaptcha.background.clear.from", "255,255,255");

        kaptchaProperties.put("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");
        kaptchaProperties.put("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
        //kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");


        Config config = new Config(kaptchaProperties);

        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);

        return defaultKaptcha;
    }
}